package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FieldData;
import com.ruoyi.system.service.IFieldDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务数据字段Controller
 * 
 * @author chenming
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/system/fieldData")
public class FieldDataController extends BaseController
{
    @Autowired
    private IFieldDataService fieldDataService;

    /**
     * 查询业务数据字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:fieldData:list')")
    @GetMapping("/list")
    public TableDataInfo list(FieldData fieldData)
    {
        startPage();
        List<FieldData> list = fieldDataService.selectFieldDataList(fieldData);
        return getDataTable(list);
    }

    /**
     * 导出业务数据字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:fieldData:export')")
    @Log(title = "业务数据字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FieldData fieldData)
    {
        List<FieldData> list = fieldDataService.selectFieldDataList(fieldData);
        ExcelUtil<FieldData> util = new ExcelUtil<FieldData>(FieldData.class);
        util.exportExcel(response, list, "业务数据字段数据");
    }

    /**
     * 获取业务数据字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fieldData:query')")
    @GetMapping(value = "/{fieldId}")
    public AjaxResult getInfo(@PathVariable("fieldId") Long fieldId)
    {
        return success(fieldDataService.selectFieldDataByFieldId(fieldId));
    }

    /**
     * 新增业务数据字段
     */
    @PreAuthorize("@ss.hasPermi('system:fieldData:add')")
    @Log(title = "业务数据字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FieldData fieldData)
    {
        return toAjax(fieldDataService.insertFieldData(fieldData));
    }

    /**
     * 修改业务数据字段
     */
    @PreAuthorize("@ss.hasPermi('system:fieldData:edit')")
    @Log(title = "业务数据字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FieldData fieldData)
    {
        return toAjax(fieldDataService.updateFieldData(fieldData));
    }

    /**
     * 删除业务数据字段
     */
    @PreAuthorize("@ss.hasPermi('system:fieldData:remove')")
    @Log(title = "业务数据字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fieldIds}")
    public AjaxResult remove(@PathVariable Long[] fieldIds)
    {
        return toAjax(fieldDataService.deleteFieldDataByFieldIds(fieldIds));
    }
}
